package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("/admin/product")
public class ManageController {

    @Autowired
    ManageService manageService;

    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){
        List<BaseCategory1> list = manageService.getCategory1();
        return Result.ok(list);
    }

    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> list = manageService.getCategory2(category1Id);
        return Result.ok(list);
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> list = manageService.getCategory3(category2Id);
        return Result.ok(list);
    }

    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(
        @PathVariable Long category1Id,
        @PathVariable Long category2Id,
        @PathVariable Long category3Id
    ){
        List<BaseAttrInfo> list = manageService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(list);
    }

    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo (
        @RequestBody BaseAttrInfo baseAttrInfo
    ){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(
        @PathVariable Long attrId
    ){
        List<BaseAttrValue> list = manageService.getAttrValueList(attrId);
        return Result.ok(list);
    }

    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result showList(
            @PathVariable Integer page,
            @PathVariable Integer limit
            ){
        IPage iPage = manageService.baseTrademark(page,limit);
        return Result.ok(iPage);
    }

    @GetMapping("/{page}/{limit}")
    public Result findList(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            Long category3Id
    ){
        IPage iPage = manageService.findSpuList(page,limit,category3Id);
        return Result.ok(iPage);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(
        @RequestBody   SpuInfo spuInfo
    ){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = manageService.getTrademarkList();
        return Result.ok(list);
    }

    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> list = manageService.baseSaleAttrList();
        return Result.ok(list);
    }

    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(
            @PathVariable Long spuId
    ){
        List<SpuImage> list = manageService.spuImageList(spuId);
        return Result.ok(list);
    }

    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(
        @PathVariable Long spuId
    ){
        List<SpuSaleAttr> list = manageService.spuSaleAttrList(spuId);
        return Result.ok(list);
    }

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @GetMapping("/list/{page}/{limit}")
    public Result skuList(
            @PathVariable Integer page,
            @PathVariable Integer limit
    ){
        IPage iPage = manageService.skuList(page,limit);
        return Result.ok(iPage);
    }

    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }

    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }
}
